package com.vidyu.businesslayer.businesscomponents;

import com.vidyu.businesslayer.businessentities.*;
import com.vidyu.datalayer.dataaccesscomponents.UserInProjectDao;
import com.vidyu.datalayer.dataaccesscomponents.EmployerDao;
import com.vidyu.datalayer.dataaccesscomponents.ProjectDao;
import com.vidyu.servicelayer.servicedataentitties.EmployerRO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * User: eyalsa
 * Date: 4/6/13
 * Time: 3:30 PM
 * To change this template use File | Settings | File Templates.
 */
@Component
public class EmployerHandler {

    @Autowired
    private EmployerDao employerDao;

    @Autowired
    private ProjectDao projectDao;

    @Autowired
    private UserInProjectDao contractorInProjectDao;

    public long addEmployer(EmployerRO employerRO) {

        Employer employer = employerDao.getEmployerByEmail(employerRO.getEmail());
        long id = Constants.NON_VALID_ID;
        if (employer == null) {
            id = employerDao.save(new Employer(employerRO.getName(), employerRO.getEmail(), employerRO.getPassword(),
                    employerRO.getAddress(), employerRO.getCountry(), employerRO.getCompanyName(),
                    employerRO.getCompanyDesc(), employerRO.getCompanyWebSite()));
        }
        return id;
    }

    public Employer getEmployerByEmailAndPassword(String email, String password) {
        return employerDao.getEmployerByEmailAndPassword(email, password);
    }

    public Employer findByID(long id) {
        return employerDao.findById(id);
    }
}
